package com.irdstudio.efp.riskm.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.riskm.service.dao.RscLoanChgHisDao;
import com.irdstudio.efp.riskm.service.domain.RscLoanChgHis;
import com.irdstudio.efp.riskm.service.facade.RscLoanChgHisService;
import com.irdstudio.efp.riskm.service.vo.RscLoanChgHisVO;
/**
 * <p>ServiceImpl: 风险分类台账变动历史表				<p>
 * @author chenqm1
 * @date 2018-05-07
 */
@Service("rscLoanChgHisService")
public class RscLoanChgHisServiceImpl implements RscLoanChgHisService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(RscLoanChgHisServiceImpl.class);

	@Autowired
	private RscLoanChgHisDao rscLoanChgHisDao;
	
	/**
	 * 新增操作
	 */
	public int insertRscLoanChgHis(RscLoanChgHisVO inRscLoanChgHisVo) {
		logger.debug("当前新增数据为:"+ inRscLoanChgHisVo.toString());
		int num = 0;
		try {
			RscLoanChgHis rscLoanChgHis = new RscLoanChgHis();
			beanCopy(inRscLoanChgHisVo, rscLoanChgHis);
			num = rscLoanChgHisDao.insertRscLoanChgHis(rscLoanChgHis);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(RscLoanChgHisVO inRscLoanChgHisVo) {
		logger.debug("当前删除数据条件为:"+ inRscLoanChgHisVo);
		int num = 0;
		try {
			RscLoanChgHis rscLoanChgHis = new RscLoanChgHis();
			beanCopy(inRscLoanChgHisVo, rscLoanChgHis);
			num = rscLoanChgHisDao.deleteByPk(rscLoanChgHis);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscLoanChgHisVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(RscLoanChgHisVO inRscLoanChgHisVo) {
		logger.debug("当前修改数据为:"+ inRscLoanChgHisVo.toString());
		int num = 0;
		try {
			RscLoanChgHis rscLoanChgHis = new RscLoanChgHis();
			beanCopy(inRscLoanChgHisVo, rscLoanChgHis);
			num = rscLoanChgHisDao.updateByPk(rscLoanChgHis);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscLoanChgHisVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public RscLoanChgHisVO queryByPk(RscLoanChgHisVO inRscLoanChgHisVo) {
		
		logger.debug("当前查询参数信息为:"+ inRscLoanChgHisVo);
		try {
			RscLoanChgHis queryRscLoanChgHis = new RscLoanChgHis();
			beanCopy(inRscLoanChgHisVo, queryRscLoanChgHis);
			RscLoanChgHis queryRslRscLoanChgHis = rscLoanChgHisDao.queryByPk(queryRscLoanChgHis);
			if (Objects.nonNull(queryRslRscLoanChgHis)) {
				RscLoanChgHisVO outRscLoanChgHisVo = beanCopy(queryRslRscLoanChgHis, new RscLoanChgHisVO());
				logger.debug("当前查询结果为:"+ outRscLoanChgHisVo.toString());
				return outRscLoanChgHisVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscLoanChgHisVO> queryAllOwner(RscLoanChgHisVO rscLoanChgHisVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscLoanChgHisVO> list = null;
		try {
			List<RscLoanChgHis> rscLoanChgHiss = rscLoanChgHisDao.queryAllOwnerByPage(rscLoanChgHisVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscLoanChgHiss.size());
			pageSet(rscLoanChgHiss, rscLoanChgHisVo);
			list = (List<RscLoanChgHisVO>) beansCopy(rscLoanChgHiss, RscLoanChgHisVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscLoanChgHisVO> queryAllCurrOrg(RscLoanChgHisVO rscLoanChgHisVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RscLoanChgHis> rscLoanChgHiss = rscLoanChgHisDao.queryAllCurrOrgByPage(rscLoanChgHisVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rscLoanChgHiss.size());
		List<RscLoanChgHisVO> list = null;
		try {
			pageSet(rscLoanChgHiss, rscLoanChgHisVo);
			list = (List<RscLoanChgHisVO>) beansCopy(rscLoanChgHiss, RscLoanChgHisVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscLoanChgHisVO> queryAllCurrDownOrg(RscLoanChgHisVO rscLoanChgHisVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscLoanChgHis> rscLoanChgHiss = rscLoanChgHisDao.queryAllCurrDownOrgByPage(rscLoanChgHisVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscLoanChgHiss.size());
		List<RscLoanChgHisVO> list = null;
		try {
			pageSet(rscLoanChgHiss, rscLoanChgHisVo);
			list = (List<RscLoanChgHisVO>) beansCopy(rscLoanChgHiss, RscLoanChgHisVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询用户权限数据
	 * create by luzhaoyu
	 */
	@SuppressWarnings("unchecked")
	public List<RscLoanChgHisVO> queryList(RscLoanChgHisVO rscLoanChgHisVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscLoanChgHisVO> list = null;
		try {
			List<RscLoanChgHis> rscLoanChgHiss = rscLoanChgHisDao.queryALLByPage(rscLoanChgHisVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscLoanChgHiss.size());
			pageSet(rscLoanChgHiss, rscLoanChgHisVo);
			list = (List<RscLoanChgHisVO>) beansCopy(rscLoanChgHiss, RscLoanChgHisVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
}
